

//
//  TheLoginViewController.h
//  HAODE
//
//  Created by panquanReabam.com on 15/9/8.
//  Copyright (c) 2015年 reabam.com. All rights reserved.

#import "TheLoginViewController.h"
#import "HttpRequest.h"
#import "RDVTabBarController.h"
#import "UIViewExt.h"
//#import "NSString+MD5.h"
#import "MyMD5.h"
#import "ForgotPasswordViewController.h"
#import "HAODEsingleton.h"
#import "RegistedViewController.h"
#import "UIImage+RTTint.h"

@interface TheLoginViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIScrollViewDelegate >
@property (retain,nonatomic)UIImageView *recordBtn;
@end

@implementation TheLoginViewController

{
    UITextField* UserNameTextField;
    UITextField* PasswordTextField;
    UIButton* chooseBtn;
    UIView*view1;
    BOOL saveAccount;
    BOOL saveAccount1;
    HAODEsingleton* commdity;
    MBProgressHUD *progressHud;
    UIView*  myToolBar;
    UIButton*agreementBtn;
    UIButton* login;
    UIScrollView*myscrollView;
}
@synthesize alt = alt;

- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@""];
    CGRect backframe = CGRectMake(0,0,23/2,41/2);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    //    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
}
-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    commdity=[HAODEsingleton shared];
    
    
    
    
    
    self.title = @"用户登录";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    
    
    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
    
    myscrollView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:myscrollView];
    
    UserNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20,60/2, ScreenWidth-40,44)];
    [UserNameTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
//   UIColor *color = [UIColor groupTableViewBackgroundColor];
    UserNameTextField.placeholder = @"请输入登录账号"; //默认显示的字
//    UserNameTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入登录账号" attributes:@{NSForegroundColorAttributeName: color}];
    UserNameTextField.font = [UIFont systemFontOfSize: 14];
    UserNameTextField.textColor= [UIColor blackColor];
    UserNameTextField.tag=22;
    
    [[UIColor whiteColor] setFill];
    UserNameTextField.keyboardType = UIKeyboardTypeDecimalPad;
    UserNameTextField.returnKeyType = UIReturnKeyDone;
    UserNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    UserNameTextField.delegate = self;
    [UserNameTextField addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    [myscrollView addSubview:UserNameTextField];
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    UserNameTextField.inputAccessoryView = myToolBar;
    
    
    PasswordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20,150/2, ScreenWidth-50, 44)];
    [PasswordTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
     PasswordTextField.placeholder = @"请输入登录密码"; //默认显示的字
//    PasswordTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入登录密码" attributes:@{NSForegroundColorAttributeName: color}];
    PasswordTextField.font = [UIFont systemFontOfSize: 14];
    PasswordTextField.textColor= [UIColor blackColor];
    PasswordTextField.secureTextEntry = YES; //密码
    PasswordTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    PasswordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    PasswordTextField.returnKeyType = UIReturnKeyDone;
    //    PasswordTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    PasswordTextField.delegate = self;
    [myscrollView addSubview:PasswordTextField];
    NSLog(@"%@",PasswordTextField.text);
    PasswordTextField.inputAccessoryView = myToolBar;
    agreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-45, 145-60, 25,25)];
    [agreementBtn setImage:[UIImage imageNamed:@"yanjing_normals"] forState:UIControlStateNormal];
    [agreementBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:agreementBtn];
    
    
    chooseBtn = [[UIButton alloc] initWithFrame:CGRectMake(18, 135, 25, 25)];
    
    NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
    NSString* UserName = [userDefault objectForKey:@"UserNameTextField"];
    NSString* Password = [userDefault objectForKey:@"passwordTextField"];
    if ([userDefault objectForKey:@"SAVEACCOUNT"]) {
             [chooseBtn setImage:[UIImage imageNamed:@"jizhumima_hight"] forState:UIControlStateNormal];
//        [chooseBtn.layer setCornerRadius:0]; //设置矩圆角半径
//        [chooseBtn.layer setBorderWidth:0.5];   //边框宽度
//        CGColorSpaceRef tureBTnSpace3 = CGColorSpaceCreateDeviceRGB();
//        CGColorRef tureBTncolorref3 = CGColorCreate(tureBTnSpace3,(CGFloat[]){204/255.0, 204/255.0, 204/255.0, 1.0});
//        [chooseBtn.layer setBorderColor:tureBTncolorref3];//边框颜色
////        chooseBtn. backgroundColor=luseColor;
        UserNameTextField.text=UserName;
        PasswordTextField.text=Password;
        saveAccount=[[userDefault objectForKey:@"SAVEACCOUNT"] boolValue];
        
    }
    else
    {
             [chooseBtn setImage:[UIImage imageNamed:@"jizhumima_normal"] forState:UIControlStateNormal];
//        [chooseBtn.layer setCornerRadius:1.0]; //设置矩圆角半径
//        [chooseBtn.layer setBorderWidth:0.5];   //边框宽度
//        CGColorSpaceRef tureBTnSpace3 = CGColorSpaceCreateDeviceRGB();
//        CGColorRef tureBTncolorref3 = CGColorCreate(tureBTnSpace3,(CGFloat[]){204/255.0, 204/255.0, 204/255.0, 1.0});
//        [chooseBtn.layer setBorderColor:tureBTncolorref3];//边框颜色
        
        UserNameTextField.text=nil;
        PasswordTextField.text=nil;
        saveAccount=[[userDefault objectForKey:@"SAVEACCOUNT"] boolValue];
    }
    
    [chooseBtn addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:chooseBtn];
    
    UIButton*jiadaagreementBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 140, 44, 44)];
    [jiadaagreementBtn addTarget:self action:@selector(chooseBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:jiadaagreementBtn];
    
    
    UILabel* Rememberthepassword=[[UILabel alloc]initWithFrame:CGRectMake(chooseBtn.right+5, 140, 120.0f, 14)];
    Rememberthepassword.text=@"记住密码";
    Rememberthepassword.font = [UIFont systemFontOfSize: 14];
    [Rememberthepassword setTextColor:zhonghuiColor];
    [myscrollView addSubview:Rememberthepassword];
    
    UIButton* forget = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-80, 140, 100.0f, 14)];
    [forget setTitle:@"忘记密码" forState:UIControlStateNormal];
    forget.titleLabel.textAlignment=NSTextAlignmentRight;
    forget.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    [forget setTitleColor: luseColor forState:UIControlStateNormal];
    forget.titleLabel.font = [UIFont systemFontOfSize: 14];
    [forget addTarget:self action:@selector(forget:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:forget];
    
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(15,148/2, ScreenWidth-30, 0.25)];
    line1.backgroundColor = labelColor;
    [myscrollView addSubview:line1];
    UILabel *line3 = [[UILabel alloc]initWithFrame:CGRectMake(15,236/2, ScreenWidth-30, 0.25)];
    line3.backgroundColor = labelColor;
    [myscrollView addSubview:line3];
    
    
    
    login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
    [login setTitle:@"登录" forState:UIControlStateNormal];
    [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [login.layer setCornerRadius:2.0]; //设置矩圆角半径
    [login.layer setBorderWidth:0.3];   //边框宽度
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204.0/255.0, 204.0/255.0, 204.0/255.0, 1.0});
    [login.layer setBorderColor:tureBTncolorref];//边框颜色
    login.backgroundColor=huisecolor;
    [myscrollView addSubview:login];
    if (UserNameTextField.text.length >1) {
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0,148/255.0, 153/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [myscrollView addSubview:login];
        
        
        
    }
    UIButton* registed = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth/2-40,540/2 ,80, 40)];
    [registed setTitle:@"立即注册" forState:UIControlStateNormal];
    [registed setTitleColor:luseColor forState:UIControlStateNormal];
    registed.titleLabel.font=[UIFont systemFontOfSize:16];
    [registed addTarget:self action:@selector(registed:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:registed];
    
    UIButton* back1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth/2-40,ScreenHeight-64-64 ,80, 40)];
    [back1 setTitle:@"返回" forState:UIControlStateNormal];
    [back1 setTitleColor:luseColor forState:UIControlStateNormal];
    [back1.layer setCornerRadius:3.0]; //设置矩圆角半径
    [back1.layer setBorderWidth:0.5];   //边框宽度
    CGColorSpaceRef registedSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref1 = CGColorCreate(registedSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
    [back1.layer setBorderColor:tureBTncolorref1];//边框颜色
    [back1 addTarget:self action:@selector(back1:) forControlEvents:UIControlEventTouchUpInside];
    //   [myscrollView addSubview:back1];
    
    
    UIButton*yanshi = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth/2-40, ScreenHeight-150, 70, 15)];
    [yanshi setTitle:@"查看演示" forState:UIControlStateNormal];
    [yanshi setTitleColor:luseColor forState:UIControlStateNormal];
    [yanshi addTarget:self action:@selector(yanshi:) forControlEvents:UIControlEventTouchUpInside];
    yanshi.titleLabel.textAlignment=NSTextAlignmentCenter;
    yanshi.titleLabel.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:yanshi];
    
    
    
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(yanshi.right,ScreenHeight-149, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [jiantou addTarget:self action:@selector(yanshi:) forControlEvents:UIControlEventTouchUpInside];
    [myscrollView addSubview:jiantou];

    
    
    
}
- (void)userNumberLimitTextLength:(UITextField*)textField
{
    if ([textField.text length] > 11)
    {
        textField.text = [textField.text substringToIndex:11];
    }
}
-(void)chooseBtn:(id)sender
{
    saveAccount1=!saveAccount1;
    if (saveAccount1) {
        UIImage *img=[UIImage imageNamed:@"yanjing_hights"];
        
        UIImage *tinted = [img rt_tintedImageWithColor:luseColor ];

        [agreementBtn setImage:tinted forState:UIControlStateNormal];
        PasswordTextField.secureTextEntry = NO; //密码
    }
    else
    {
        [agreementBtn setImage:[UIImage imageNamed:@"yanjing_normals"] forState:UIControlStateNormal];
        PasswordTextField.secureTextEntry =YES; //密码
    }
    
}

-(void)chooseBtn1:(id)sender
{
    saveAccount=!saveAccount;
    if (saveAccount) {
             [chooseBtn setImage:[UIImage imageNamed:@"jizhumima_hight"] forState:UIControlStateNormal];
//        chooseBtn. backgroundColor=luseColor;
    }
    else
    {
              [chooseBtn setImage:[UIImage imageNamed:@"jizhumima_normal"] forState:UIControlStateNormal];
//        chooseBtn. backgroundColor=nil;
    }
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    
    if (textField.tag ==22){
        
        
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [myscrollView addSubview:login];
        
        
        
        
    }
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [textField resignFirstResponder];
    if (textField.tag ==22){
        if (textField.text.length == 0) {
            [login removeFromSuperview];
            login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
            [login setTitle:@"登录" forState:UIControlStateNormal];
            [login setTitleColor:qianhuicolor forState:UIControlStateNormal];
            login.backgroundColor=luseColor;
            [login.layer setCornerRadius:3.0]; //设置矩圆角半径
            [login.layer setBorderWidth:0.3];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
            [login.layer setBorderColor:tureBTncolorref];//边框颜色
            [myscrollView addSubview:login];
            
            
            
        }
        
        if (textField.text.length >1) {
            [login removeFromSuperview];
            login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
            [login setTitle:@"登录" forState:UIControlStateNormal];
            [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            login.backgroundColor=luseColor;
            [login.layer setCornerRadius:3.0]; //设置矩圆角半径
            [login.layer setBorderWidth:0.3];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
            [login.layer setBorderColor:tureBTncolorref];//边框颜色
            [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
            [myscrollView addSubview:login];
            
            
        }
    }
    return YES;
}
-(void)forget:(UIButton*)sender{
    
    ForgotPasswordViewController* forget=[[ForgotPasswordViewController alloc]init];
    [self.navigationController pushViewController:forget animated:YES];
    
    
    
}
-(void)back1:(UIButton*)sender{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}
-(void)registed:(UIButton*)sender{
    
    RegistedViewController* Login=[[RegistedViewController alloc]init];
    
    [self.navigationController pushViewController:Login animated:YES];
    
    
}


-(void)yanshi:(UIButton*)sender{
    UserNameTextField.text =@"13999999999";
    PasswordTextField.text=@"reabam";
    [Global showIndeterminateHud:@"登录中，请稍后..." delay:30 view:self.view];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:UserNameTextField.text forKey:@"mobile"];
    [params setValue: [MyMD5 md5:PasswordTextField.text] forKey:@"loginWord"];
    
    //            NSLog(@"====%@",params);
    [HttpRequest requestData1:@"System/Login" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            //                    NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                [UserNameTextField resignFirstResponder];
                [PasswordTextField resignFirstResponder];
                
                [Global hideProgressHUDInternal:self.view];
                NSString* md5  = [MyMD5 md5:PasswordTextField.text];
                //                        NSLog(@"%@",md5);
                
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"] objectForKey:@"serverAddress"] forKey:@"AppUrls"];
                
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"tokenId" ] forKey:@"tokenId"];
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userCode" ] forKey:@"userCode"];
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userName" ] forKey:@"userName"];
                
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"companyName" ] forKey:@"companyName"];
                [user setObject:[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userAudit" ]] forKey:@"userAudit"];
                
                [user setObject:[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"groupId" ]] forKey:@"groupId"];
                
                [user setObject:PasswordTextField.text forKey:@"Password"];
                [user setObject:UserNameTextField.text forKey:@"UserNameTextField"];
                [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userType" ]  forKey:@"userType"];
                
                [user synchronize];
                
                commdity.Dictss=nil;
                commdity.Dicts=nil;
                if ([commdity.shouye isEqualToString:@"shouye"]) {
                    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
                    
                }else{
                    
                    [self.navigationController popViewControllerAnimated:YES];
                }
                
                
                
                if (saveAccount) {
                    
                    
                    [user setBool:saveAccount forKey:@"SAVEACCOUNT"];
                    
                    [user setObject:PasswordTextField.text forKey:@"passwordTextField"];
                    
                    [user synchronize];
                    
                    
                }
                else
                {
                    
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passwordTextField"];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SAVEACCOUNT"];
                    [[NSUserDefaults standardUserDefaults] synchronize];
                }
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
                
                NSString* md5  = [MyMD5 md5:PasswordTextField.text];
                NSLog(@"%@",md5);
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
}


-(void)login:(UIButton*)sender{
    
    if ([UserNameTextField.text length] <1)
    {
        [self showAlertMessage:@"请输入账号"];
    }
    else{
        
        
        if ([PasswordTextField.text length] < 1)
        {
            [self showAlertMessage:@"请输入密码"];
        }
        else
        {
            
            
            [Global showIndeterminateHud:@"登录中，请稍后..." delay:30 view:self.view];
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:UserNameTextField.text forKey:@"mobile"];
            [params setValue: [MyMD5 md5:PasswordTextField.text] forKey:@"loginWord"];
            
            NSLog(@"====%@",params);
            [HttpRequest requestData1:@"System/Login" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        
                
                        [Global hideProgressHUDInternal:self.view];
                        
                        [UserNameTextField resignFirstResponder];
                        [PasswordTextField resignFirstResponder];
                        
                        [Global hideProgressHUDInternal:self.view];
                        NSString* md5  = [MyMD5 md5:PasswordTextField.text];
                        NSLog(@"%@",md5);
                        
                        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                         [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"companyId" ] forKey:@"companyId"];
                        
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"tokenId" ] forKey:@"tokenId"];
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userCode" ] forKey:@"userCode"];
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userName" ] forKey:@"userName"];
                        
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"companyName" ] forKey:@"companyName"];
                        [user setObject:[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userAudit" ]] forKey:@"userAudit"];
                        
                        [user setObject:[NSString stringWithFormat:@"%@",[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"groupId" ]] forKey:@"groupId"];
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"] objectForKey:@"serverAddress"] forKey:@"AppUrls"];
                        
                        [user setObject:PasswordTextField.text forKey:@"Password"];
                        [user setObject:UserNameTextField.text forKey:@"UserNameTextField"];
                        [user setObject:[[severDataDict.dataDict objectForKey:@"DataLine"]objectForKey:@"userType" ]  forKey:@"userType"];
                        
                        [user synchronize];
                        
                        commdity.Dictss=nil;
                        commdity.Dicts=nil;
                        if ([commdity.shouye isEqualToString:@"shouye"]) {
                            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
                            
                       
                        
                     
                        
                        
                        
                        }else{
                            
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                        
                        
                        
                        if (saveAccount) {
                            
                            
                            [user setBool:saveAccount forKey:@"SAVEACCOUNT"];
                            
                            [user setObject:PasswordTextField.text forKey:@"passwordTextField"];
                            
                            [user synchronize];
                            
                            
                        }
                        else
                        {
                            
                            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passwordTextField"];
                            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SAVEACCOUNT"];
                            [[NSUserDefaults standardUserDefaults] synchronize];
                        }
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        NSString* md5  = [MyMD5 md5:PasswordTextField.text];
                        NSLog(@"%@",md5);
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }}
}
- (void)back:(UIButton *)msg
{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user removeObjectForKey:@"Token"];
    [user synchronize];
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)OnTapDone{
    [UserNameTextField resignFirstResponder];
    [PasswordTextField resignFirstResponder];
    if (UserNameTextField.text.length == 0) {
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        login.backgroundColor=huisecolor;
        [myscrollView addSubview:login];
        
        
    }
    
    if (UserNameTextField.text.length >1) {
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [myscrollView addSubview:login];
        
    }
    
    
    
}
//回收键盘
-(void)closeKeyBoad
{
    [UserNameTextField resignFirstResponder];
    [PasswordTextField resignFirstResponder];
    if (UserNameTextField.text.length == 0) {
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setBackgroundColor:huisecolor];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [login.layer setCornerRadius:2.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [myscrollView addSubview:login];
        
        
    }
    
    if (UserNameTextField.text.length >1) {
        [login removeFromSuperview];
        login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2-64, ScreenWidth-20, anniuHeigth)];
        [login setTitle:@"登录" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login.layer setCornerRadius:2.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [myscrollView addSubview:login];
        
        
    }
    
    
}


@end
